<div class="x_panel">
  <div class="x_content" style="display: block;">
    <!--<div class="nav navbar-right panel_toolbox">
      <a class="fa fa-plus" href="/student/add.html">设置账号</a>
    </div>-->
    <br><br>
    <div class="row-fluid">
      <form action="/student/index.html" method="get">
        <div class="col-md-3 col-sm-3 col-xs-3">
          <label class="control-label">昵称</label>
          <input type="text" class="form-control-new" name="form[nick_name]" value="{if isset($query.nick_name)}{$query.nick_name}{/if}">
        </div>
        <div class="col-md-3 col-sm-3 col-xs-3">
          <label class="control-label">状态</label>
          <select  class="form-control-new" name="form[user_status]" >
            <option {if !isset($query.user_status) || $query.user_status==-1}selected="selected"{/if} value="-1">全部</option>
            <option {if isset($query.user_status) && $query.user_status==1}selected="selected"{/if} value="1">学生</option>
            <option {if isset($query.user_status) && $query.user_status==0}selected="selected"{/if} value="0">游客</option>
          </select>
        </div>
        <div class="col-md-4 col-sm-4 col-xs-4">
          <label class="control-label">联系方式</label>
          <input type="text" class="form-control-new" name="form[mobile]" value="{if isset($query.mobile)}{$query.mobile}{/if}">
        </div>
        <button type="submit" class="btn btn-primary" style="">搜索</button>
      </form>
    </div>
    <br><br>
    <!--表格主体内容-->
    <div class="cont">
      <table class="table table-bordered table-striped">
        <thead>
        <tr>
          <th width="100px">ID</th>
          <th>昵称</th>
          <th>状态</th>
          <th>联系方式</th>
          <th>邮箱</th>
          <th>入学时间</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach $student.lists as $studentitem}
        <tr>
          <td>{$studentitem.user_id}</td>
          <td>{base64_decode($studentitem.nick_name)}</td>
          <td>{if $studentitem.user_status==1}学生{else}游客{/if}</td>
          <td>{$studentitem.mobile}</td>
          <td>{$studentitem.email}</td>
          <td>{if $studentitem.in_time}{date('Y-m-d',strtotime($studentitem.in_time))}{/if}</td>
          <td>
            <div class="x_content">
              <button class="set-password btn btn-primary btn-xs" data="{$studentitem.user_id}" data-username="{$studentitem.username}" data-password="{$studentitem.password}"> 设置账号</button>
              <a class="btn btn-primary btn-xs" href="{eval U(['user/answer','user_id'=>$studentitem.user_id])}"> 答题记录</a>

            </div>
          </td>
        </tr>
        {/foreach}
        </tbody>
      </table>
      <!--分页-->
      {Yii::$app->view->render('/com/pager.php',['pager'=>$student.pager])}
    </div>
  </div>
</div>
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="detail-modal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header" style="border:none">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></button>
        <h4 class="modal-title" id="myModalLabel">设置账号</h4>
      </div>
      <div class="modal-body">
        <div class="loaders">
          <div class="ball-spin-fade-loader">
            账号：<input id="username" type="text" value="" />
            <br>
            密码：<input id="password" type="text" value="" />
          </div>
        </div>
        <div id="modal-dyn"></div>
      </div>
      <div class="modal-footer" style="border:none;">
        <button id="setpassword" type="button" class="copy btn btn-secondary" data="">提交</button>
        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
      </div>
    </div>
  </div>
</div>
<script>
    $(".set-password").click(function () {
        $('#setpassword').attr('data',$(this).attr('data'));
        $('#username').text($(this).attr('data-username'));
        $('#password').text($(this).attr('data-password'));
        $('#detail-modal').modal('show');
    })

    $("#setpassword").click(function () {
        var user_id = $(this).attr('data');
        var username = $('#username').val();
        var password = $('#password').val();
        var url = "{['student/set-password']|U}";
        $.post(url, 'user_id='+user_id+'&username='+username+'&password='+password, function (data) {
            window.location.reload();
        },'json');
        $('#detail-modal').modal('hide');
    })
</script>
